{layout name="main"/}
<style>
    .modal-backdrop,
    .fade,
    .in {
        display: none;
    }
</style>
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">

                <div class="ibox-title">
                    <h5>会员审核列表</h5>

                </div>

                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-sm-4">
                            <button class="btn btn-primary btn-xs" id="selectAll"><i class="fa fa-check"></i> 全选 </button>
                            <button class="btn btn-warning btn-xs" id="deleteAll"><i class="fa fa-trash"></i> 批量删除 </button>

                            <button class="btn btn-primary btn-xs" id="confirmAll"><i class="fa fa-check"></i> 开通会员 </button>
                        </div>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input type="text" placeholder="搜索(会员编号,会员昵称，推荐人)" class="input-sm form-control" name="keyword" value="{$keyword}"> <span class="input-group-btn">
                                    <button type="button" class="btn btn-sm btn-primary" onclick="search()">搜索</button> </span>
                            </div>
                        </div>
                    </div>
                    <div class="project-list">
                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable" id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
                            <thead>
                                <tr role="row">
                                    <th style="width: 5%">选择</th>
                                    <th style="width: 12%;">申请会员编号</th>
                                    <th style="width: 10%;">会员昵称</th>
                                    <th style="width: 10%;">电话</th>
                                    <th style="width: 10%;">类型</th>
                                    <th style="width: 15%;">推荐人</th>

                                    <th style="width: 15%;">注册时间</th>
                                    <th style="width: 5%;">状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>

                            <!--                            <tbody><tr class="no-records-found"><td colspan="8">没有找到匹配的记录</td></tr></tbody>-->

                            <tbody>
                              {:table_empty_list($list,'暂无数据!',9)}

                                {volist name="list" id="vo"}
                                <tr class="gradeA odd">
                                    <td>
                                        <input type="checkbox" class="i-checks" value="{$vo->user_id}" name="ids[]">
                                    </td>

                                    <td class=" ">{$vo->user_uniid}</td>
                                    <td class="center ">{$vo->user_name}</td>
                                    <td class="center ">{$vo->phone}</td>
                                    <td class=" ">{$vo->account_type}</td>
                                    <td class=" ">
                                        {$vo->parent_user->user_name|default="/"} {if $vo->parent_user->phone}({$vo->parent_user->phone}){/if}
                                    </td>


                                    <td class="center ">{$vo->create_time}</td>
                                    <td class="center"><span class="badge badge-danger">{$vo.user_status}</span></td>
                                    <td class="center">
                                        <button class="btn btn-warning btn-xs" data-toggle="modal" data-target="#myModal{$vo->user_id}">查看详细</button>
                                        {if condition="session('user')->user_type!='agent'"}<a href="{:url('admin/User/editUser',['user_id'=>$vo->user_id])}" class="btn btn-warning btn-xs">修改信息</a>{/if}
                                        <button class="btn btn-danger btn-xs" onclick="delUser({$vo->user_id})"><i class="fa fa-trash"></i> 删除 </button>
                                        <button class="btn btn-primary btn-xs" onclick="confirmUser({$vo->user_id})"><i class="fa fa-check-square-o"></i> 通过 </button>

                                    </td>
                                </tr>
                                {/volist}

                            </tbody>

                        </table>

                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" id="DataTables_Table_0_info" role="alert" aria-live="polite" aria-relevant="all">
                                    每页显示 {:getPageSize()} 项，共 {$list->toArray()['total']} 项</div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                    {$list->render()}

                                </div>

                            </div>
                        </div>

                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

{volist name="list" id="vo"}
<div class="modal inmodal fade" id="myModal{$vo->user_id}" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">会员信息</h4>
            </div>
            <div class="modal-body">
                <p>
                    推荐人： {$vo->parent_user->user_name|default="/"} {$vo->parent_user->user_uniid} {if $vo->parent_user->phone}({$vo->parent_user->phone}){/if}
                </p>

                <p>
                    会员编号：{$vo->user_uniid}
                </p>
                <p>
                    会员昵称：{$vo->user_name}
                </p>

                <p>
                    银行卡信息：[{$vo->vaild_card->bank_name}] {if $vo->vaild_card->card_sub_bank}[{$vo->vaild_card->card_sub_bank}]{/if} [{$vo->vaild_card->card_name}] [{$vo->vaild_card->card_number}]
                </p>
                <p>
                    身份证号码：{$vo->id_number}
                </p>
                <p>
                    联系电话：{$vo->phone}
                </p>
                <p>
                    注册时间：{$vo->create_time}
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>

            </div>
        </div>
    </div>
</div>
{/volist}

<script>
    $(document).ready(function() {
        $(".i-checks").iCheck({
            checkboxClass: "icheckbox_square-green",
            radioClass: "iradio_square-green",
        });
        $("#selectAll").on('click', function(event) { //如果是选中，点击后则为不选中
            $(".i-checks").iCheck('check');
        });
        $("#deleteAll").click(function() {
            swal({
                title: "您确定要删除这条信息吗",
                text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "删除",
                closeOnConfirm: false,
                cancelButtonText: "取消",
            }, function() {
              var postdata = '';
              if ($("input[type='checkbox']:checked").length == 0) {
                  swal("错误", "请至少选择1个会员。", "error");
                  return;
              }
              $("input[type='checkbox']:checked").each(function() {

                  postdata = postdata==''?'ids[]=' + $(this).val():postdata + '&ids[]=' + $(this).val();
              });
                if (postdata != '') {
                    post({
                        url: "{:url('admin/User/del_multi')}",
                        data: postdata,
                        success: function(res) {
                            swal({
                                title: 'success',
                                text: res.message,
                                type: "success"
                            }, function() {
                                reload();
                            });
                        },
                        error: function(error) {
                            swal("错误", JSON.parse(error.responseText).message, "error");
                        }
                    });
                }
            });
        });
        $("#confirmAll").click(function() {
            swal({
                title: "您确定要通过这些会员的认证吗?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#18a689",
                confirmButtonText: "通过",
                closeOnConfirm: false,
                cancelButtonText: "取消",
            }, function() {
                var postdata = '';
                if ($("input[type='checkbox']:checked").length == 0) {
                    swal("错误", "请至少选择1个会员。", "error");
                    return;
                }
                $("input[type='checkbox']:checked").each(function() {

                    postdata = postdata==''?'ids[]=' + $(this).val():postdata + '&ids[]=' + $(this).val();
                });
                if (postdata != '') {
                    post({
                        url: "{:url('admin/User/confirm_multi')}",
                        data: postdata,
                        success: function(res) {
                            swal({
                                title: 'success',
                                text: res.message,
                                type: "success"
                            }, function() {
                                reload();
                            });
                        },
                        error: function(error) {
                            swal("错误", JSON.parse(error.responseText).message, "error");
                        }
                    });
                }
            });
        });
    });

    function delUser(id) {
        if (confirm("您是否确认删除?")) {
            post({
                url: "{:url('admin/User/del',[],'')}/user_id/" + id,
                success: function(res) {
                    swal({
                        title: 'success',
                        text: res.message,
                        type: "success"
                    }, function() {
                        reload();
                    });
                },
                error: function(error) {
                    swal("错误", JSON.parse(error.responseText).message, "error");
                }
            });
        }

    }

    function confirmUser(id) {
        if (confirm("您是否确认通过此用户认证?")) {
            post({
                url: "{:url('admin/User/confirm',[],'')}/user_id/" + id,
                success: function(res) {
                    swal({
                        title: 'success',
                        text: res.message,
                        type: "success"
                    }, function() {
                        reload();
                    });
                },
                error: function(error) {
                    swal("错误", JSON.parse(error.responseText).message, "error");
                }
            });
        }
    }

    function search() {
        var url = "{:url('admin/User/checkUserList', [],'')}";
        var keyword = $("input[name=keyword]").val();
        if (keyword != "") {
            url = url + "/keyword/" + keyword;
        }
        toUrl(url);
    }
</script>
